home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Patterned Curve ƒ / patterned curve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  4.2 KB  |  139 lines  |  [TEXT/KAHL]

  1. /*
  2.     patterned curve.c
  3.     
  4.     This file contains the calls to create a "thick" curve and fill it will a "star" as the pattern.
  5.         
  6.     NOTES:
  7.     • This file requires the new "GX"-ified interface files and libraries. With the interface files, all types and function
  8.     names are proceeded by a "gx" for types or "GX" for function names.
  9.     
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c", "graphics debug library.c", "transform library.c".
  12.         
  13.     • This file prints the "best" in landscape mode.
  14.     
  15.     ©1992 - 1994  Apple Computer, Inc.
  16.     All rights reserved.
  17. */
  18.  
  19. #include <events.h>
  20. #include <windows.h>
  21.  
  22. #include "font library.h"
  23. #include "graphics debugging.h"
  24. #include "graphics libraries.h"
  25. #include "graphics toolbox.h"
  26. #include "graphics shell.h"
  27.  
  28. //
  29. //  Set up the title and size of the window 
  30. //
  31. Str255     gWindowTitle = "\p Patterned Curve";
  32. Rect         gWindowQDRect  = {50, 20, 235, 375};
  33.  
  34. //
  35. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the NewGraphicsClient routine
  36. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  37. //    With  gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  38. //
  39. long        gGraphicsHeapSize = 25;
  40.  
  41. gxShape     gShape;
  42.  
  43. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  44.  
  45. void DoInitialization(gWindow)
  46. WindowPtr gWindow;
  47. {
  48.     gxCurve             curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  49.     gxShape            starShape, testRect;
  50.     gxRectangle        starShapeBounds;
  51.     gxPatternRecord    starPattern;
  52.     
  53.     long starGeometry[] = {1, //  number of contours
  54.                         5, //  number of points 
  55.                           ff(60), 0, ff(90), ff(90),  ff(0), ff(30),  ff(120), ff(30), ff(0), ff(90)};   //  the points
  56.      
  57.      InitCommonColors();
  58.  
  59.     gShape = GXNewCurve (&curveGeometry);
  60.     
  61.     //
  62.     // Create a star gxShape which will be used as the fill pattern
  63.     //
  64.     starShape =  GXNewPolygons((gxPolygons *) starGeometry);
  65.      GXScaleShape(starShape, fl(0.25), fl(0.25), 0, 0);
  66.  
  67.     //
  68.     //    Get the bounds of our star gxShape.  We use the bounds to setup the u and v vectors of the pattern 
  69.     //    record. We want "gShape" to be filled  with the star where each star is placed at edge of the
  70.     //    previous star (i.e so the pattern's do not overlap).
  71.     //    
  72.      GXGetShapeBounds(starShape, 0L, &starShapeBounds);
  73.  
  74.     starPattern.u.x = 0;
  75.     starPattern.u.y = starShapeBounds.bottom;
  76.      starPattern.v.x = starShapeBounds.right + fixed1;
  77.     starPattern.v.y = 0;
  78.  
  79.     starPattern.attributes = gxPortAlignPattern;
  80.     starPattern.pattern = starShape;
  81.  
  82.     GXSetShapePattern(gShape, &starPattern);
  83.     
  84.     //
  85.     //    We can dispose of our star gxShape because it is now referenced from within the
  86.     //    pattern record contained in "gShape".
  87.     //
  88.      GXDisposeShape (starShape);
  89.     
  90.     SetShapeCommonColor (gShape, blue);
  91.     GXSetShapePen (gShape, ff(75));
  92.     GXMoveShape (gShape,  ff(50), 0);
  93. }
  94.  
  95. /*------ DoClick ---------------------------------------------------------------------------------------*/
  96.  
  97. void DoClick( orgMouseLoc, theWindow )
  98. gxPoint        orgMouseLoc;
  99. WindowPtr     theWindow;
  100. {
  101. }
  102.  
  103.  
  104. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  105.  
  106. void DoDraw(gWindow)
  107. WindowPtr gWindow;
  108. {
  109.     GXDrawShape (gShape);
  110. }
  111.  
  112.  
  113. /*------ DoDispose -------------------------------------------------------------------------------------*/
  114.  
  115. void DoDispose(gWindow)
  116. WindowPtr gWindow;
  117. {
  118.     /**  
  119.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  120.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  121.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  122.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  123.         can turn notices on in this file by setting gDebugging = TRUE (above).
  124.     **/
  125.     GXDisposeShape(gShape);  
  126.      GXDisposeShape(gWindowBoundsShape);  
  127.        DisposeCommonColors();
  128.        DisposeWindow(gWindow);
  129. }
  130.     
  131.  
  132.  
  133. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  134.  
  135. void DoIdle(gWindow)
  136. WindowPtr gWindow;
  137. {
  138. }
  139.